package com.designoutput.ui.editors
{
	import com.designoutput.elements.BaseElement;
	
	import flash.display.Sprite;

	public class BaseEditor extends Sprite
	{
		protected var selectedElements:Vector.<BaseElement>;
		
		public function BaseEditor() {
			selectedElements = new Vector.<BaseElement>();
		}
		
		public function setElements(elements:Array):void {
			var element:BaseElement;
			for each(element in selectedElements)
				removeElement(element);

			for each(element in elements)
				addElement(element);
		}
		
		private function addElement(element:BaseElement):void {
			if(selectedElements.indexOf(element) == -1){
				selectedElements.push(element);
				onElementAdded(element);
				onElementsChanged();
			}
		}
		
		private function removeElement(element:BaseElement):void {
			var index:int = selectedElements.indexOf(element);
			if(index != -1){
				selectedElements.splice(index, 1);
				onElementRemoved(element);
				onElementsChanged();
			}
		}
		
		protected function onElementAdded(element:BaseElement):void {
			
		}
		
		protected function onElementRemoved(element:BaseElement):void {
			
		}
		
		protected function onElementsChanged():void {
			
		}
		
		public function mouseDownOnElement(element:BaseElement):void {
		}
	}
}